package Deom2;
abstract class Animal{
    private String name;
    private int age;

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }
    public abstract void eat();
}
    class Dog extends Animal{
        public Dog(String name, int age) {
            super(name, age);
        }

        @Override
        public void eat() {
            System.out.println(this.getName() +"吃狗粮");
        }
    }
class Cat extends Animal{
    public Cat(String name, int age) {
        super(name, age);
    }

    @Override
    public void eat() {
        System.out.println(this.getName()+"吃猫粮");
    }
}

public class Test3 {
    public static void func(Animal a){
        a.eat();
    }
    public static void main(String[] args) {
        Animal[] a = {new Dog("大飞",3),new Cat("白糖",3)};
        for (Animal x:a) {
           x.eat();
        }
    }
}
